package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.ListOfAwardsResponse
import com.gexiaobao.pigeon.databinding.ItemListOfAwardsBinding

/**
 * @Author      : hxw
 * @Date        : 2024/7/19 10:36
 * @Describe    :
 */
class AdapterListOfAwards(data: ArrayList<ListOfAwardsResponse>) :
    BaseQuickAdapter<ListOfAwardsResponse, DataBindBaseViewHolder>(R.layout.item_list_of_awards, data) {

    private var mOnItemGroupClickListener: OnItemGroupClickListener? = null

    @SuppressLint("NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: ListOfAwardsResponse) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemListOfAwardsBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        holder.setGone(R.id.tvItemNoDataText, !item.itemList.isNullOrEmpty())

        holder.itemView.apply {
            binding.swipeRecyclerView.adapter = null
            val mAdapter = AdapterListOfAwardsNames()
            mAdapter.setList(item.itemList)
            binding.swipeRecyclerView.apply {
                layoutManager = LinearLayoutManager(context)
                adapter = mAdapter
                mAdapter.notifyDataSetChanged()
            }

            mAdapter.setOnItemClickListener(object : AdapterListOfAwardsNames.OnItemClickListener {
                override fun onItemClick(projectId: Int, groupTitle: String) {
                    mOnItemGroupClickListener?.onItemClick(projectId, item.projectName, groupTitle, item.type)
                }
            })
        }
    }

    fun setOnItemGroupClickListener(listener: OnItemGroupClickListener?) {
        mOnItemGroupClickListener = listener
    }

    interface OnItemGroupClickListener {
        fun onItemClick(projectId: Int, projectName: String, groupTitle: String, type: Int)
    }
}